'use strict';
module.exports = {
	/**
	 * 获取我的发布列表
	 * @url client/bbs/pub/getMySquareList 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, bbs_status } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------

		// 要关联取出 评论条数
		let dbName = "bbs_article";
		res = await vk.baseDao.selects({
			dbName,
			data,
			getMain: false, // 是否只返回rows数据
			pageIndex: data.pageNo, // 当前第几页
			pageSize: data.pageSize, // 每页条数
			whereJson: { uid, bbs_status },
			sortArr: [
				{ "name": "_add_time", "type": "desc" }
			],
			fieldJson: {
				content: true,
				uid: true,
				category_id: true,
				images: true,
				_add_time: true,
				like_count: true
			},
			foreignDB: [{
				dbName: "user-bbs-tumbup",
				localKey: "_id",
				foreignKey: "posts_id",
				as: "tumbups",
				fieldJson: { _id: true }
			}, {
				dbName: "user-bbs-tumbup",
				localKey: "_id",
				foreignKey: "posts_id",
				as: "tumbup",
				fieldJson: { _id: true },
				whereJson: {
					user_id: uid
				},
				limit: 1,
			}, {
				dbName: "user-bbs-star",
				localKey: "_id",
				foreignKey: "posts_id",
				as: "star",
				fieldJson: { _id: true },
				whereJson: {
					user_id: uid
				},
				limit: 1,
			}, {
				dbName: "uni-id-users",
				localKey: "uid",
				foreignKey: "_id",
				as: "user",
				fieldJson: { nickname: true, avatar: true },
				limit: 1,
			}, {
				dbName: "bbs_comments",
				localKey: "_id",
				foreignKey: "aid",
				as: "comments",
				foreignDB: [{
					dbName: "uni-id-users",
					localKey: "uid",
					foreignKey: "_id",
					as: "user",
					fieldJson: { nickname: true, avatar: true },
					limit: 1,
				}],
			}]
		});

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
